# -*- coding: utf-8 -*-
from multiprocessing import Pool
import ping,MySQLdb,time
psize = 64
timeout = 2
worker_processes=30
def do_somthing_using(arguments):
	bAlive=ping.do_one(arguments[0],timeout,psize)
	if bAlive!=None:
		# print arguments[0],"ok"
		return arguments[0],1
	else:
		# print arguments[0],"timeout"
		return arguments[0],0
if __name__ == '__main__':
# 从mysql的rnd表取ndip数据
	conn=MySQLdb.connect(host="172.16.100.31",user="root",passwd="admin",db="rainbow_3_0")
	cursor=conn.cursor()
# cursor.execute("select dscfgnwipaddr from rnd order by dscfgnwipaddr desc limit 10")
	cursor.execute("select dscfgnwipaddr from rnd order by dscfgnwipaddr")
	nds=cursor.fetchall()
	cursor.close()
	conn.close()
	print len(nds)
	pool = Pool(processes=worker_processes)              # start 4 worker processes
	start=time.time()
	result=[x.get() for x in [pool.apply_async(do_somthing_using, (x,)) for x in nds]]

	print time.time()-start          # prints "100" unless your computer is *very* slow
	for x in result:
		if x[1]==0:
			print x[0]